package org.libraq.hrm.web.controller;

import org.libraq.hrm.doc.CourseDoc;
import org.libraq.hrm.dto.CourseSearchDto;
import org.libraq.hrm.repository.CourseElasticsearchRepository;
import org.libraq.hrm.service.ICourseEsSearch;
import org.libraq.hrm.util.AjaxResult;
import org.libraq.hrm.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CourseEsController {
    @Autowired
    private CourseElasticsearchRepository courseElasticsearchRepository;
    @Autowired
    private ICourseEsSearch courseEsSearch;

    @RequestMapping(value = "/es/course",method = RequestMethod.POST)
    public AjaxResult save(@RequestBody CourseDoc doc){
        courseElasticsearchRepository.save(doc);
        return AjaxResult.me();
    }

    /**
     * 课程主站的查询接口
     * @param dto
     * @return
     */
    @RequestMapping(value = "/es/searchCourse",method = RequestMethod.POST)
    public AjaxResult searchCourse(@RequestBody CourseSearchDto dto){
        PageList<CourseDoc> pageList = courseEsSearch.searchCourse(dto);
        return AjaxResult.me().setResultObj(pageList);
    }

}
